#include <vector>
#include <iostream>
#include "stack.h"

using namespace std;
#ifdef ISTACK
iStack::iStack(void)
{
	_top = 0;
	cout << "default constuctor" << endl;
}

iStack::iStack(const iStack &c)
{
	_stack = c._stack;
	_top = c._top;

	cout << "iStack copy constructor" << endl;
}

iStack::~iStack()
{
    cout << "iStack destructor" << endl;
}

bool iStack::pop(int &value)
{
    if(empty())
    {
        return false;
    }
    try
    {
        value = _stack.at(_top - 1);
        _top--;
        cout << "stack::pop--" << value << endl;
    }
    catch(...)
    {
        cout << "istack overflow" << endl;
    }

    return true;
}

bool iStack::push(int value)
{
	if(full()) return false;

    _stack[_top++] = value;
	cout << "stack::push--" << value << endl;

	return true;
}

void iStack::display(void)
{
	if(size() == 0) 
	{
		cout << "(0)" << endl;
		return;
	}

	cout << "(" << size() << ") (Start ";
	for(int i = 0; i < size(); i++) cout << _stack.at(i) << " ";
	cout << " end)" << endl;
}
#endif
//******************************************/
//test
static iStack test1(const iStack c)
{
    return c;
}

static iStack test2(const iStack &c)
{
    return c;
}

static iStack test3(void)
{
    static iStack c(2);

    return c;
}

static iStack &test4(void)
{
    static iStack c(2);

    return c;
}

void stack_test(void)
{
    int i = 0;
    iStack ustack;          // 1 default constructor
    iStack estack = ustack; // 1 copy constructor
    iStack astack, b;       // 2 default constructor

    test1(astack);          // 2 copy constructor
    test2(astack);			// 1 copy constructor function return
    b = test3();			// 1 copy constructor
    b = test4();

    test1(iStack(2));       // 1 copy constructor  ??
    test2(iStack(2));       // 1 copy constructor

    ustack.display();

    for(i = 0; i < 20; i++)
    {
        ustack.push(i);
    }

    ustack.display();

    ustack.pop(i);
    ustack.pop(i);

    ustack.display();
}
